package matlab;

public class DoubleArrayVariable extends AbstractVariable {

	double[] value;
	int[] dim;
	
	public DoubleArrayVariable(String name, double[] value) {
		super(name);
		this.value = value;
		dim = new int[] { 1, value.length };
	}
	
	public DoubleArrayVariable(String name, double[] value, int dim1, int dim2) {
		super(name);
		this.value = value;
		dim = new int[] { dim1, dim2 };
	}
	
	@Override
	public ArrayType getType() {
		return ArrayType.DOUBLE;
	}

	@Override
	public int[] getDimensions() {
		return dim;
	}
	
	@Override
	public double[] getDoubleArray() {
		return value;
	}

	@Override
	public boolean isDouble() {
		return true;
	}
	
	public static double[] transpose(double[] arr, int dim1, int dim2)
	{
		double[] x = new double[arr.length];
		for (int i = 0; i < dim1; i++) {
			for (int j = 0; j < dim2; j++) {
				x[j+i*dim2] = arr[i+j*dim1];
			}
		}
		return x;
	}
}
